﻿using Freebase4net.Interfaces;
using Freebase4net.Operators;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
namespace Freebase4net
{
    public class MqlParser
    {
        #region constructor

        private readonly StringBuilder _sb;
        private static Dictionary<object, object> _query;


        public string JsonString { get { return _sb.ToString(); } private set { value = string.Empty; } }

        public MqlParser(dynamic query)
        {
            _query = new Dictionary<object, object>();
            FillPreperties(query);

            _sb = new StringBuilder();
            GenerateMqlString();
        }

        private void FillPreperties(dynamic query)
        {
                IDictionary<string, object> q = (IDictionary<string, object>)query;
                foreach (var item in q)
                {
                    _query.Add(item.Key, item.Value);
                }
            
            
        }

        #endregion

        private void GenerateMqlString()
        {

            _sb.Append(JsonGenerationHelpers.FromDictionary(_query, false));

            JsonString = _sb.ToString();
        }
    }
}